<?php
/**
 * created by zzy
 * date: 2018/1/6 15:46
 */


namespace App\Http\Admin\Process\Controllers;
use Framework\BaseClass\Http\Admin\Controller;
use App\Eloquent\Ygt\ProcessField;
use App\Eloquent\Ygt\OrderField;
use App\Eloquent\Ygt\OrderFieldCompany;
use DB;

class OrderController extends Controller
{

    //工单第一步字段列表
    public function lists()
    {
        $adminUser         = request()->user('admin')->toArray();
        $companyId         = $adminUser['company_id'];

        if (request()->isMethod('post')) {

            $title          = request( 'title', '' );
            $where          = [];
            if( $title )
            {
                $where['title']      = ['like','%'.$title.'%'];
            }
            $lists          = OrderField::getCompanyFieldList($companyId,$where);
            $result         = collect($lists)->toJson();
            return $result;
        } else {

            $toolbarItem       = $companyId == 1 ? 'add' : '';
            $fieldTypeList   = ProcessField::getFieldTypeList( 4 );
            return $this->view('lists', compact('toolbarItem','fieldTypeList') );
        }
    }
    //工单第一步字段修改添加
    public function edit()
    {
        if (!request()->isMethod('post')) { exit('error'); }
        $adminUser         = request()->user('admin')->toArray();
        $companyId         = $adminUser['company_id'];

        $params             = $this->requestJson();
        $result             = OrderField::editCompanyField($companyId, $params);
        if( $result === 'exist' ){
            return $this->ajaxFail('名字已存在');
        } else if( $result === true ){
            return $this->ajaxSuccess('成功');
        } else {
            return $this->ajaxFail('失败');
        }
    }
    //厂工单第一步字段列表
//    public function companyList()
//    {
//        $adminUser         = request()->user('admin')->toArray();
//        $companyId         = $adminUser['company_id'];
//
//        if (request()->isMethod('post')) {
//
//            $title          = request( 'title', '' );
//            $where          = ['company_id'=>$companyId];
//            if( $title )
//            {
//                $where['title']      = ['like','%'.$title.'%'];
//            }
//            $lists          = OrderFieldCompany::getFieldList($companyId,$where);
//            $result         = collect($lists)->toJson();
//            return $result;
//        } else {
//
//            $fieldTypeList   = ProcessField::getFieldTypeList( 4 );
//            return $this->view('set', compact('fieldTypeList') );
//        }
//    }
    //厂工单第一步字段修改
//    public function companyEdit()
//    {
//        if (!request()->isMethod('post')) { exit('error'); }
//        $adminUser         = request()->user('admin')->toArray();
//        $companyId         = $adminUser['company_id'];
//
//        $params             = $this->requestJson();
//        if(!isset($params['id']))
//        {
//            return $this->ajaxFail('参数不全');
//        }
//        $result             = OrderFieldCompany::editField($companyId,$params);
//        if( $result === 'exist' ){
//            return $this->ajaxFail('名字已存在');
//        } else if( $result === true ){
//            return $this->ajaxSuccess('成功');
//        } else {
//            return $this->ajaxFail('失败');
//        }
//    }
}